<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      xmlns:form="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <link rel="shortcut icon" th:href="@{/favicon.ico}" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
</head>
<body class="login-bg">

    <div class="login layui-anim layui-anim-up">
        <div class="message">登录</div>
        <div id="darkbannerwrap"></div>

        <form th:action="@{/login}" method="post" class="layui-form" >
            <input name="username" id="username" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" ><!-- 注册账号 -->
            <hr class="hr15">
            <input name="password" id="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input"><!-- 忘记密码 -->
            <hr class="hr15">
            <!--<input name="rememberPassword" id="rememberPassword" type="checkbox" title="记住密码" lay-skin="primary">-->
            <input name="rememberMe" id="rememberMe" type="checkbox" title="自动登录" lay-skin="primary">
            <hr class="hr15">
            <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
        </form>
    </div>

    <script th:src="@{/js/jquery-3.2.1.min.js}"></script>
    <script th:src="@{/plugins/layui/layui.js}" charset="utf-8"></script>
    <script th:src="@{/js/xadmin.js}"></script>
    <script layout:fragment="js_fragments">
        $(function () {
            layui.use('form', function(){
                var form = layui.form;
                // layer.msg('玩命卖萌中', function(){
                //   //关闭后的操作
                //   });
                //监听提交
                form.on('submit(login)', function(data){
                    //layer.msg(JSON.stringify(data.field));
                    var username = data.field.username;
                    var password = data.field.password;
                    var rememberMe = JSON.stringify(data.field.rememberMe)?true:false;
                    $.post('login',{"username":username,"password":password,"rememberMe":rememberMe},function(result){
                        //layer.msg(result.code+'---'+result.msg);
                        if(result.code == 1002){
                            location.href = 'index';
                        }else{
                            layer.msg(result.msg);
                        }
                    })
                    return false;
                });
                return false;
            });
        });
    </script>
</body>
</html>